/*
 * @Descripttion: 
 * @Author: yubo
 * @Date: 2022-07-08 14:51:53
 * @LastEditTime: 2022-09-27 13:58:10
 */
#include "Utility.h"
#include <fstream>
#include <sstream>
#include <atomic>

std::vector<std::string> Utility::ReadLinesFromFile(const std::string filename)
{
	std::ifstream fs;
	fs.open(filename);

	std::vector<std::string> lines;
	if (!fs.is_open())
	{
		return lines;
	}

	std::string oneline;
	while (getline(fs, oneline))
	{
		if (oneline.empty())
		{
			continue;
		}

		lines.emplace_back(oneline);
	}
	fs.close();

	return lines;
}

std::string Utility::ReadContentsFromFile(const std::string filename)
{
	std::fstream fs;
	fs.open(filename);
	if (!fs.is_open())
		return "";

	std::ostringstream oss;
	oss << fs.rdbuf();
	fs.close();
	return oss.str();
}

#ifdef _WIN32
long long Utility::get_curr_micro_second_count()
{
	LARGE_INTEGER tm, freq;
	QueryPerformanceFrequency(&freq);
	QueryPerformanceCounter(&tm);

	tm.QuadPart *= 1000000;
	tm.QuadPart /= freq.QuadPart;
	return tm.QuadPart;
}
#endif